package it.polimi.meteocal.ejb.notificationmanagement;

import it.polimi.meteocal.ejb.usermanagement.User;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 * Entity implementation class for Entity: PacchettoEntity
 *
 */
@Entity
@Table(name="NOTIFICATION")
@NamedQueries({
	@NamedQuery(name=Notification.FIND_ALL,
				query="SELECT i FROM Notification i "),
	@NamedQuery(name=Notification.findUserNotifications,
				query="SELECT n FROM Notification n WHERE n.user.email = :email"),
	@NamedQuery(name=Notification.deleteById,
				query="DELETE FROM Notification n WHERE n.notificationid = :notificationid")
})

public class Notification {

	public Notification() {
		super();
	}

	private static final long serialVersionUID = 1L;
	
	public static final String FIND_ALL = "Notification.findAll";
	public static final String findUserNotifications = "Notification.findUserNotifications";
	public static final String deleteById = "Notification.deleteById";
	
	@Id
	@GeneratedValue (strategy=GenerationType.IDENTITY)
	private int notificationid;
	
	private String text;
	
	private String type;
	
	@ManyToOne
	@JoinTable(name = "nhasUser",
		inverseJoinColumns={@JoinColumn(name="userEmail",referencedColumnName="email")}, joinColumns={@JoinColumn(name="notificationid", referencedColumnName="notificationid")})
	private User user;

	public Notification(NotificationDTO nuovo){
        
        this.notificationid		= nuovo.getNotificationid();
        this.text				= nuovo.getText();
        this.type  				= nuovo.getType();
        
    }

	

	public int getNotificationid() {
		return notificationid;
	}



	public void setNotificationid(int notificationid) {
		this.notificationid = notificationid;
	}



	public String getText() {
		return text;
	}



	public void setText(String text) {
		this.text = text;
	}



	public String getType() {
		return type;
	}



	public void setType(String type) {
		this.type = type;
	}



	public User getUser() {
		return user;
	}



	public void setUser(User user) {
		this.user = user;
	}



	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public static String getFindAll() {
		return FIND_ALL;
	}

	public static String getFindusernotifications() {
		return findUserNotifications;
	}
	
}
